package com.carl.zlds.tool.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtil {
    public DateUtil() {
    }

    public static Long time() {
        return System.currentTimeMillis() / 1000L;
    }

    public static String timeFormat(long time) {
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(time * 1000L);
        return formatter.format(date);
    }

    public static String timeFormat(long time, String format) {
        DateFormat formatter = new SimpleDateFormat(format);
        Date date = new Date(time * 1000L);
        return formatter.format(date);
    }

    public static Long timeFormat(String dateStr) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);

        try {
            return formatter.parse(dateStr).getTime();
        } catch (ParseException var3) {
            var3.printStackTrace();
            return null;
        }
    }
}
